#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;

const int N = 2e5 + 10;

int n, k;
LL a[N];

void solve(){
    cin >> n >> k;
    for(int i = 1; i <= n; i ++) cin >> a[i];

    LL res = 0;
    if(k <= n){
        LL k1 = 0, maxv = 0;

        for(int i = 1; i <= k; i ++){
            k1 = k1 + a[i];
        }
        maxv = max(maxv, k1);

        for(int i = k + 1; i <= n; i ++){
            k1 = k1 - a[i - k] + a[i];
            maxv = max(maxv, k1);
        }

        res = maxv + (LL)(k - 1) * k / 2;
    }else{
        for(int i = 1; i <= n; i ++){
            res = res + a[i];
        }

        LL ff = k - n + 1;
      //  cout << "ff: " << ff << '\n';
        res = res + ff - 1;
        res = res + ff * (n - 1) + (LL)(n - 2) * (n - 1) / 2;
    }

    cout << res << '\n';
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        solve();
    }    


    return 0;
}